package com.ufida.ebscg.comm;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <p>Title: TianYi BBS</p>
 * <p>Description: EBSCG System</p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: www.ufida.com.cn</p>
 * @author guoxp
 * @version 6.0
 */

public class UserCheck {
	private static final Log logger = LogFactory.getLog(UserCheck.class);

	private SysInfo si;
	private HttpServletRequest request;
	private HttpServletResponse response;
	private String username = "";
	private String usernamedes = "";
	private String nickname = "";
	private long id = 0;
	private String authCode = "";
	private static final String EGSCG_AI_KEY = "AI";

	//  private DES des;
	//UserInfo userInfo = null;

	public UserCheck() {
		
	}

	public void addC(String name, String value) {
		Cookie cookies = new Cookie(name, value);
		cookies.setPath(si.getCookiepath());
		cookies.setMaxAge(-1);
		//cookies.setMaxAge(30 * 60);
		if (si.getCookiedomain() != null && si.getCookiedomain().length() > 0) {
			cookies.setDomain(si.getCookiedomain());
		}
		this.response.addCookie(cookies);
	}

	public void addAuthCode() {
		this.authCode = Util.genNumPassword(4);
		addC(EGSCG_AI_KEY, this.authCode);
	}

	public UserCheck(HttpServletRequest request, HttpServletResponse response) {
		this.request = request;
		this.response = response;
		this.si = SysInfo.getInstance();
		try {
			//des = new DES(DES._DESede);
		} catch (Exception ex) {
			logger
					.error("UserCheck(HttpServletRequest request, HttpServletResponse response,"
							+ " ServletContext sc)" + ex);
		}
		getCookies(request, response);
	}

	public void getCookies(HttpServletRequest request,
			HttpServletResponse response) {
		Cookie cookies[] = request.getCookies();
		Cookie sCookie = null;
		byte[] buf;
		try {

		} catch (Exception e) {
			this.username = "";
			this.usernamedes = "";
			//e.printStackTrace();
			logger
					.error("getCookies(HttpServletRequest request,HttpServletResponse response)"
							+ e);
		}
	}

	  public String getAuthCode() {
	    return authCode;
	  }
	

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsernamedes() {
		return usernamedes;
	}

	public void setUsernamedes(String usernamedes) {
		this.usernamedes = usernamedes;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public boolean isLoginPass() {
		return false;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	/**
	   public UserInfo getUserInfo() {
	  return userInfo;
	   }

	   public void setUserInfo(UserInfo userInfo) {
	  this.userInfo = userInfo;
	   }*/

}
